//
//  MyViewController.m
//  ProfilePicture
//
//  Created by 张云江 on 2019/10/17.
//  Copyright © 2019年 张云江. All rights reserved.
//

#import "MyViewController.h"
#import "MyTableViewCell.h"
#import "MyHeaderView.h"
#import "ServiceView.h"

#import "VipViewController.h"

@interface MyViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;

@end

@implementation MyViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)setNav
{
    self.customNavBar.title = @"设置";
}

- (void)creatUI
{
    [self.view addSubview:self.tableView];
    self.tableView.sd_layout.spaceToSuperView(UIEdgeInsetsMake(kNavigationHeight, 0, 0, 0));
}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.bounces = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.backgroundColor = kUIColorFromRGB(0xF7F7F7);
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return kRatio(65);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return kRatio(120);
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return kRatio(10);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyTableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    if (cell == nil) {
        cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    cell.iconName = @[@"my_1",@"my_2",@"my_3",@"my_4",@"my_5",@"my_6"][indexPath.row];
    cell.titleName = @[@"VIP会员",@"联系客服",@"去评分",@"版本号",@"隐私政策",@"服务协议"][indexPath.row];
    cell.row = indexPath.row;
    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[MyHeaderView alloc] init];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc] init];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            VipViewController *vc = [[VipViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            ServiceView *serviceView = [[ServiceView alloc] initWithFrame:[UIScreen mainScreen].bounds];
            [[[UIApplication sharedApplication].delegate window] addSubview:serviceView];
        }
            break;
        case 2:
        {
            NSString *nsStringToOpen = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id1484017288?action=write-review"];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:nsStringToOpen]];
        }
            break;
        case 3:
        {
            
        }
            break;
        case 4:
        {
            WebViewController *webVc = [[WebViewController alloc] init];
            webVc.titles = @"隐私政策";
            webVc.requestFullURL = kPrivacyPolicy;
            [self.navigationController pushViewController:webVc animated:YES];
        }
            break;
        case 5:
        {
            WebViewController *webVc = [[WebViewController alloc] init];
            webVc.titles = @"服务条款";
            webVc.requestFullURL = kTermsofUse;
            [self.navigationController pushViewController:webVc animated:YES];
        }
            break;
            
        default:
            break;
    }
}
@end
